package com.panghl.test02.service;


import com.panghl.entity.User;
import com.panghl.test01.mapper.UserMapper01;
import com.panghl.test02.mapper.UserMapper02;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
public class UserService02 {
    @Resource
    private UserMapper02 userMapper02;
    @Resource
    private UserMapper01 userMapper01;
    public User findByName(String name){
        return userMapper02.findByName(name);
    }

    @Transactional(transactionManager = "test02DataSourceTransactionManager")
    public int insert(String username,String password,Integer age){
        int insert = userMapper02.insert(username, password);
        int i = 1/age;
        return insert;
    }

    public int insertUserTest01AndTest02(String username,String password,Integer age){
        // 传统分布式事务解决方案 jta+atomikos  注册到一个全局事务中

        int insert2 = userMapper01.insert(username, password);
        int i = 1/age;
        int insert1 = userMapper02.insert(username, password);
        return insert1+insert2;
    }

}
